package com.caigou.controller;

import com.caigou.bean.cms.entity.Us;
import com.caigou.bean.cms.param.UsParam;
import com.caigou.bean.exam.entity.Users;
import com.caigou.enums.ResponseEnum;
import com.caigou.security.utils.CurrentUser;
import com.caigou.service.UsService;
import com.caigou.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/us/")
public class UsController {

    @Resource
    private UsService usService;

    @RequestMapping("listUs")
    @PreAuthorize("hasAnyAuthority('wangzhanmingpian')")
    public Result listUs(@CurrentUser Users user){
        List<Us> usList = usService.listUs();
        return Result.success(usList);
    }


    @RequestMapping("getUs")
    @PreAuthorize("hasAnyAuthority('wangzhanmingpian')")
    public Result getUs(@RequestBody UsParam usParam, @CurrentUser Users user){
        Us us = usService.selectByPrimaryKey(usParam.getId());
        return Result.success(us);
    }


    @RequestMapping("saveAndPublishUs")
    @PreAuthorize("hasAnyAuthority('wangzhanmingpian')")
    public Result saveAndPublishUs(@RequestBody UsParam usParam, @CurrentUser Users user){
        return usService.saveAndPublishUs(usParam);
    }
}
